package com.bank.user.controller;

import com.bank.model.vo.login.LoginVo;
import com.bank.model.vo.login.RegisterVo;
import com.bank.user.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.util.Map;

/**
 * @author Cejay1314
 * @version 1.0
 * @create 2023/3/20 16:48
 */

@RestController
@RequestMapping(value = "/user")
public class LoginController {
    @Autowired
    UserService userService;


    @GetMapping
    public String hello(){
        return "hello";
    }

    //    用户登录
    @PostMapping("/login")
//    we must add the annotation @RequestBody so that we can transform json to java object. Or it will be null
    public Map<String,String> login(@RequestBody LoginVo loginVo){
        return userService.login(loginVo);
    }

    //    注册用户
    @PostMapping(value = "/register")
    @ResponseBody
    public void register(@RequestBody RegisterVo registerVo){
        userService.register(registerVo);
    }

    //    退出登录
    @GetMapping("/logout")
//    we must add the annotation @RequestBody so that we can transform json to java object. Or it will be null
    public void logout(HttpServletRequest httpServletRequest){
        userService.logout(httpServletRequest);
    }


}
